package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Product;
import com.by.bean.ProductHistory;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.query.HistoryQuery;
import com.by.query.ProductCustomerQuery;
import com.by.query.ProductQuery;
import com.by.service.ProductHistoryService;
import com.by.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "浏览历史")
@RequestMapping("/v1")
public class ProductHistoryController extends BaseController {

    @Autowired
    ProductHistoryService productHistoryService;


    @ApiOperation("浏览记录")
    @PostMapping("/product/history")
    public ResultBean queryHistory(@RequestBody HistoryQuery historyQuery) {
        Map<String, Object> map = BeanUtil.beanToMap(historyQuery);
        PageBean bean = productHistoryService.queryHistory(map);
        return success("浏览历史", bean);
    }

    @ApiOperation("产品详情")
    @GetMapping("/product/historyDetail")
    public ResultBean detail(@RequestParam("pid") int pid) {
        ProductHistory productHistory = productHistoryService.get(pid);
        return success("产品详情", productHistory);
    }
}
